import 'package:flutter/material.dart';
import 'res/listData.dart';
import 'dart:math';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // ThemeData 是flutter用于定义应用主题样式的类
      // 你可以通过它设置颜色、字体、按钮样式等全局风格。
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.red), // 主色
        brightness: Brightness.light, // 亮色主题
        fontFamily: 'Roboto', // 字体
        useMaterial3: true, // 建议开启Material3
        appBarTheme: const AppBarTheme(
          backgroundColor: Colors.red, // 背景色
          foregroundColor: Colors.black, // 字体颜色
        ),
      ),
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter app'),
          //backgroundColor: Theme.of(context).colorScheme.primary, // 强制使用主题颜色
        ),
        body: MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  ListView _initListViewData() {
    List<Widget> tmpList = [];
    for (var i = 0; i < 20; i++) {
      tmpList.add(ListTile(title: Text("我是一个列表$i")));
    }
    return ListView(padding: EdgeInsets.only(top: 50), children: tmpList);
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;

    return Stack(
      children: [
        _initListViewData(),
        Positioned(
          left: 0,
          top: 0,
          width: size.width, // 配置子元素宽度
          height: 44, // // 配置子元素高度
          child: Row(
            children: [
              Expanded(
                flex: 1,
                child: Container(
                  alignment: Alignment.center,
                  color: Colors.black,
                  child: const Text(
                    "二级导航",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
              Expanded(
                flex: 2,
                child: Container(
                  alignment: Alignment.center,
                  color: Colors.yellow,
                  child: const Text(
                    "二级导航",
                    style: TextStyle(color: Colors.white),
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }
}
